<?php include "conn.php";?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>最新资讯-新闻资讯-<?php echo $SiteTitle;?></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> -->
    <meta name="keywords" content="最新资讯-新闻资讯-<?php echo $SiteKeywords;?> ">
    <meta name="description" content="最新资讯-新闻资讯-<?php echo $SiteDescription;?> " />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <?php include "public/cssjs.php";?>
    <link rel="stylesheet" type="text/css" href="/css/news.css" />
</head>
<body>
<?php include "public/top.php";?>
<?php
if(isset($_GET["orderby"])){
    $orderby=$_GET["orderby"];
}else{
    $orderby="adate";
}
$conn=new Mysql();
$sql = "select * from news_shop where type=1 order by ".$orderby." desc";
$page_size = 9;					 //定义每页显示多少记录
$num_cnt = mysqli_num_rows($conn->query($sql)); //获取总记录数
$page_cnt = ceil($num_cnt/$page_size);  //计算总页数
if(isset($_GET["page"])){
    $page = intval($_GET["page"]);
}else{
    $page = 1;
}
if ($page<1)
{
    $page=1;
}
elseif ($page>$page_cnt)
{
    $page=$page_cnt;
}
$query_start = ($page - 1 ) * $page_size;   //计算每页开始的记录号
$query_sql = $sql." limit $query_start,$page_size"; //使用limit获取记录
?>
<!--  -->
<div class="home-m home-productList">
    <div class="container">
        <div class="home-heading">
            <div class="home-title"><span>新闻资讯</span></div>
        </div>
        <div class="tab row">
            <div class="col-md-3 mb-4">
                <div class="dropdown show">
                    <span>
                        排队：
                    </span>
                    <a class="btn btn-secondary dropdown-toggle" href="?orderby=adate" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        最新
                    </a>

                    <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                        <a class="dropdown-item" href="?orderby=adate">最新</a>
                        <a class="dropdown-item" href="?orderby=LinkCount">最多关注</a>
                    </div>
                </div>
            </div>
            <div class="col-md-9 mb-4">
                <div class="page text-center text-md-right">
                    <nav aria-label="Page navigation example">
                        <?php Pagefenye($num_cnt,$page_cnt,$page);?>
                    </nav>
                </div>
            </div>
        </div>
        <div class="home-body">
            <div class="masonry">

                <?php

                if($num_cnt>0)
                {
                    $i=1;
                    $row=$conn->getAll($query_sql);
                    foreach($row as $key=>$rs) {

                        ?>
                        <div class="item">
                            <div class="item_content content-lar">
                                <a href="view.php?id=<?php echo $rs["id"];?>">
                                    <div class="pic">
                                        <img src="/pic/<?php echo $rs["pic"];?>" alt="<?php echo $rs["title"];?>" onerror="this.src='/pic/error.jpg'">
                                    </div>
                                    <?php
                                    if($i %2==0){
                                       ?>

                                        <div class="content">
                                            <div>
                                                <div class="name"><?php echo $rs["title"];?></div>
                                                <div class="info"><?php echo $rs["author"];?> <?php echo date("Y-m-d",strtotime($rs["adate"]));?></div>
                                                <div class="details"><?php echo killword($rs["title_f"],70);?></div>
                                            </div>
                                        </div>

                                        <?php
                                    }else{
                                       ?>
                                        <div class="name"><?php echo $rs["title"];?></div>
                                        <div class="info"><?php echo $rs["author"];?> <?php echo date("Y-m-d",strtotime($rs["adate"]));?></div>
                                        <div class="details"><?php echo killword($rs["title_f"],70);?></div>

                                        <?php

                                    }
                                    ?>

                                </a>
                            </div>
                        </div>

                        <?php
                        $i++;
                    }

                }

                ?>

            </div>
        </div>
    </div>

    <div class="page">
        <nav aria-label="Page navigation example">
            <?php Pagefenye($num_cnt,$page_cnt,$page);?>
        </nav>
    </div>
</div>
<!--  -->


<?php include "public/footer.php";?>
<?php include "public/bottom.php";?>
</body>

</html>